﻿using System.Web.Mvc;
using IInject;
using IInject.Practices.ServiceLocation;
using LogikBug.ModularMvc;
using LogikBug.ModularMvc.Hosting;
using LogikBug.ModularMvc.Registration;
using Microsoft.Practices.ServiceLocation;
using Test.Entities;

namespace Test.Site
{
	public class MvcApplication : ModularMvcApplication<WebsiteModule>
	{
		protected override void Application_Start()
		{
			ViewEngines.Engines.Clear();
			ViewEngines.Engines.Add(new RazorViewEngine());

			base.Application_Start();
		}

		protected override sealed void InitializeServiceLocator()
		{
			var locator = new Container();
			locator.Set<AssemblyResourceProvider>();
			locator.Set<DynamicTypeModelBinder>();
			locator.Set<IRegistrationContext, RegistrationContext>();
			locator.Set<IControllerFactory, ModuleControllerFactory>();
			var serviceLocator = new IInjectServiceLocator(locator);
			ServiceLocator.SetLocatorProvider(() => serviceLocator);
			DependencyResolver.SetResolver(serviceLocator);
		}

		//protected override IEnumerable<ILocation> GetLocations()
		//{
		//    var locations = base.GetLocations().ToList();
		//    locations.Add(LocationFactory.Instance.FromCodegenDir());
		//    return locations;
		//}

		protected override string GetConnectionStringName()
		{
			return "ControlPanelConnectionString";
		}
	}
}